package com.niit.controller.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;

import org.springframework.data.redis.core.StringRedisTemplate;




import redis.clients.jedis.JedisPoolConfig;
/*spring boot 有默认配置可以直接获取redis_template 先注释掉*/
//@Configuration
public class JedisConfig {
	@Value("${spring.redis.host}")
	private String host;
	@Value("${spring.redis.port}")
	private Integer port;
	@Value("${spring.redis.password}")
	private String password;
	
	@Value("${spring.redis.pool.max-active}")
	private Integer maxActive;
	@Bean
	public JedisConnectionFactory convertFactory(){
		JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
		jedisConnectionFactory.setHostName(host);
		jedisConnectionFactory.setPort(port);
		jedisConnectionFactory.setPassword(password);
		
		JedisPoolConfig jedisPoolConfig= new JedisPoolConfig();
		jedisPoolConfig.setMaxTotal(maxActive);
		
		
		return jedisConnectionFactory;
	}
	@Bean
	public StringRedisTemplate convertTemplate(){
		StringRedisTemplate stringRedisTemplate = 
				new StringRedisTemplate(convertFactory());
		return stringRedisTemplate;
		
	}
	
	/*
	@Bean
	public RedisTemplate<String, CourseDTO> convertCourseTemplate(){
		RedisTemplate<String, CourseDTO> redisTemplate = 
				new RedisTemplate<>(convertFactory());
	}*/
}
